<div class="admin">
    <div class="tab panel dux-box admin-panel">
        <div class="panel-head"><strong>优惠券管理</strong></div>
        <div class="padding border-bottom">
            <a href="JavaScript:void(0);" class="button button-small border-green">管理</a>
            <a href="{:U('add')}" class="button button-small border-green">添加</a>
            <a href="{:U('send')}" class="button button-small border-green">发放代金券</a>
        </div>

        <div class="table-tools clearfix ">
            <div class="float-left">
                <form method="get" action="{:U('index')}" name="formSearch" id="formSearch">
                    <div class="form-inline">
                        <div class="form-group">
                            <div class="field"><label>商户名：</label>
                                <input class="input input_big" type="text" name="keywrods" value="{$keywords}">
                            </div>
                            <div class="field"><label>有效期时间：</label>
                                <input class="input input_big hasDatepicker" type="text" value="" id="query_start_time" name="query_start_time" readonly="readonly">至
                                <input class="input input_big hasDatepicker" type="text" value="" id="query_end_time" name="query_end_time" readonly="readonly">
                            </div>
                        </div>
                        <div class="form-button">
                            <button class="button bg-blue" type="submit">查询</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>

        <form method="post" action="" name="myForm" id="myForm">
            <table class="table tb-type2 nobdb">
                <thead>
                    <tr class="thead">
                        <th class="align-center">编号</th>
                        <th class="align-center">活动名称</th>
                        <th class="align-center">店铺名称</th>
                        <th class="align-center">开始时间</th>
                        <th class="align-center">结束时间</th>
                        <th class="align-center">代金券金额</th>
                        <th class="align-center">使用额度</th>
                        <th class="align-center">可发放数</th>
                        <th class="align-center">限领数</th>
                        <th class="align-center">已领取</th>
                        <th class="align-center">已使用</th>
                        <th class="align-center">创建日期</th>
                        <th class="align-center">状态</th>
                        <th class="align-center">操作</th>
                    </tr>
                </thead>
                <tbody>
                <foreach item="v" name="list">
                    <tr class="hover">
                        <td class="align-center">{$v['voucher_id']}</td>
                        <td>{$v['voucher_title']}</td>
                        <td class="align-center">{$v['voucher_storename']}</td>
                        <td class="align-center">{$v['voucher_start_date']|date='Y-m-d H:i:s',###}</td>
                        <td class="align-center">{$v['voucher_end_date']|date='Y-m-d H:i:s',###}</td>
                        <td class="align-center">{$v['voucher_price']}</td>
                        <td class="align-center">{$v['voucher_limit']}</td>
                        <td class="align-center">{$v['voucher_total']}</td>
                        <td class="align-center">{$v['voucher_eachlimit']}</td>
                        <td class="align-center"><a href="{:U('Voucher/giveout',array('voucher_id'=>$v['voucher_id']))}">{$v['voucher_giveout']}</a></td>
                        <td class="align-center"><a href="{:U('Voucher/used',array('voucher_id'=>$v['voucher_id']))}">{$v['voucher_used']}</a></td>
                        <td class="align-center">{$v['voucher_add_date']|date='Y-m-d H:i:s',###}</td>
                        <td class="nowrap align-center">
                            <switch name="v.voucher_state">
                    <case value="1">有效</case>
                    <case value="2">失效</case>
                    <default />
                    </switch>
                    </td>
                    <td class="w144 align-center">
                        <a class="button bg-blue button-little" href="{:U('edit',array('voucher_id'=>$v['voucher_id']))}"><i class="icon-edit"></i>修改</a>
                        <a class="button bg-red button-little js-del" href="javascript:;" data="{$v['voucher_id']}" title="删除"><i class="icon-minus-circle"></i>删除</a>
                        <a class="button bg-green button-little js-qrcode" href="javascript:;" data-voucherid="{$v['voucher_id']}"><i class="icon-download"></i>二维码</a>
                        <!-- 删除 -->
                    </td>
                    </tr>
                </foreach>
                </tbody>
                <tfoot>
                    <tr class="tfoot">
                        <td colspan="15"><div class="pages clearfix">{$page}</div></td>
                    </tr>
                </tfoot>
            </table>
        </form>
    </div>
</div>
<script type="text/javascript">
    $('#myForm').layer({
        actionUrl: "batchAction",
        deleteUrl: "del",
    });
    $('#query_start_time').duxTime({
        format: "Y-m-d H:i"
    });
    $('#query_end_time').duxTime({
        format: "Y-m-d H:i"
    });

    $('.js-qrcode').on('click', getData);
    function getData() {
        var voucher_id = $(this).data('voucherid');
        $.ajax({
            url: "{:U('/Voucher/download')}", //写接口
            data: {voucher_id: voucher_id},
            type: "get",
            success: function (data) {
                if (data) {
                	layer.open({
                                type: 2,
                                title: '很多时候，我们想最大化看，比如像这个页面。',
                                shadeClose: true,
                                shade: false,
                                maxmin: true, //开启最大化最小化按钮
                                area: ['250px', '250px'],
                                content: data
                          });
                } else {
                    layer.msg('二维码生成失败……', {icon: 5});
                }
            }
        })
    }
</script>